// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   AATHandler.java

package cn.sendsms;

import java.io.IOException;
import java.lang.reflect.Constructor;

// Referenced classes of package cn.sendsms:
//			TimeoutException, GatewayException, ModemGateway, MessageClasses, 
//			AsyncEvents

abstract class AATHandler
{

	static final int DELAY_AT = 200;
	static final int DELAY_RESET = 20000;
	static final int DELAY_CMD_MODE = 1000;
	static final int DELAY_CMGS = 100;
	ModemGateway gateway;
	String storageLocations;
	String description;
	String terminators[];
	String asyncEventResponse;

	public AATHandler(ModemGateway gateway)
	{
		this.gateway = gateway;
		storageLocations = "";
	}

	String getDescription()
	{
		return description;
	}

	void setStorageLocations(String loc)
	{
		storageLocations = loc;
	}

	String getStorageLocations()
	{
		return storageLocations;
	}

	String[] getTerminators()
	{
		return terminators;
	}

	abstract void sync()
		throws IOException, InterruptedException;

	abstract void reset()
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract void echoOff()
		throws IOException, InterruptedException;

	abstract void init()
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract boolean isAlive()
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract String getSimStatus()
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract boolean enterPin(String s)
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract boolean setVerboseErrors()
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract boolean setPduProtocol()
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract boolean setTextProtocol()
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract boolean setIndications()
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract String getManufacturer()
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract String getModel()
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract String getSerialNo()
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract String getImsi()
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract String getSwVersion()
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract String getBatteryLevel()
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract String getSignalLevel()
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract boolean setMemoryLocation(String s)
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract void switchToCmdMode()
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract boolean keepGsmLinkOpen()
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract int sendMessage(int i, String s, String s1, String s2)
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract String listMessages(MessageClasses messageclasses)
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract boolean deleteMessage(int i, String s)
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract String getGprsStatus()
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract String send(String s)
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract String getNetworkRegistration()
		throws GatewayException, TimeoutException, IOException;

	abstract void readStorageLocations()
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	abstract AsyncEvents processUnsolicitedEvents(String s)
		throws IOException;

	abstract String getAsyncEventResponse(AsyncEvents asyncevents)
		throws TimeoutException, GatewayException, IOException, InterruptedException;

	static AATHandler load(ModemGateway gateway, String gsmManuf, String gsmModel)
		throws RuntimeException
	{
		String BASE_HANDLER = (cn.sendsms.ATHandler.class).getName();
		String handlerClassNames[] = {
			null, null, BASE_HANDLER
		};
		String handlerDescriptions[] = {
			null, null, "Generic"
		};
		StringBuffer handlerClassName = new StringBuffer(BASE_HANDLER);
		if (gsmManuf != null && gsmManuf.length() != 0)
		{
			handlerClassName.append("_").append(gsmManuf);
			handlerClassNames[1] = handlerClassName.toString();
			handlerDescriptions[1] = gsmManuf + " (Generic)";
			if (gsmModel != null && gsmModel.length() != 0)
			{
				handlerClassName.append("_").append(gsmModel);
				handlerClassNames[0] = handlerClassName.toString();
				handlerDescriptions[0] = gsmManuf + " " + gsmModel;
			}
		}
		AATHandler atHandler = null;
		for (int i = 0; i < 3; i++)
			try
			{
				if (handlerClassNames[i] == null)
					continue;
				Class handlerClass = Class.forName(handlerClassNames[i]);
				Constructor handlerConstructor = handlerClass.getConstructor(new Class[] {
					cn.sendsms.ModemGateway.class
				});
				atHandler = (AATHandler)handlerConstructor.newInstance(new Object[] {
					gateway
				});
				atHandler.description = handlerDescriptions[i];
				break;
			}
			catch (Exception ex)
			{
				if (i == 2)
				{
					ex.printStackTrace();
					throw new RuntimeException("Class AbstractATHandler: Cannot initialize handler!");
				}
			}

		return atHandler;
	}
}
